package com.traffic.between.adaptor;


import java.util.Date;

import org.apache.log4j.Logger;

import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.BetweenProperties;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.LinKeServiceImpl;
import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONObject;

@ChooseProvider(channel = "linke")
public class LinKeAdaptor implements IAdaptor{

	private static Logger log = Logger.getLogger(LinKeAdaptor.class);

	public void order() {
		
	    OrderBean orderBean = OrderInfoContext.getContext();
	    orderBean.setSendTime(new Date());
		String pkgNo = orderBean.getProductCode();
		String phoneNo = orderBean.getPhoneNo();
		String tradeNo = orderBean.getIds();//订购流水号
		String notifyUrl = BetweenProperties.CALLBACK_URL+"Linke";
		
		
		String result = LinKeServiceImpl.service.order(pkgNo,phoneNo,tradeNo,notifyUrl);
		log.info("林科訂購請求返回結果："+result);
		
		JSONObject json = JSONObject.fromObject(result);

		String err = json.getString("err");//状态码

		if ("0".equals(String.valueOf(err))) {
			orderBean.setStatus("10");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		}
		
		BsmOrderResultExecutor.service.setOrder(orderBean);

	}
	
	
}
